package com.cxh.mediasessiondemo;

import android.content.Context;
import android.media.browse.MediaBrowser;
import android.view.View;

import com.cxh.mediasessiondemo.adapter.CommonRVHolder;
import com.cxh.mediasessiondemo.adapter.CommonRvAdapter;
import com.cxh.mediasessiondemo.adapter.IAdapterViewItem;

/**
 * Created by Cxh
 * Time : 2021/10/23  01:50
 * Desc :
 */
public class MusicRvAdapter extends CommonRvAdapter<MediaBrowser.MediaItem> {

    private int mCurrentIndex;

    public void setCurrentIndex(int currentIndex) {
        mCurrentIndex = currentIndex;
        notifyDataSetChanged();
    }

    public MusicRvAdapter(Context context) {
        super(context);
    }

    @Override
    protected IAdapterViewItem<MediaBrowser.MediaItem> getAdaperItem(int position) {
        return new IAdapterViewItem<MediaBrowser.MediaItem>() {
            @Override
            public int getLayoutRes() {
                return R.layout.item_music_info;
            }

            @Override
            public void onBindView(CommonRVHolder<MediaBrowser.MediaItem> holder) {

            }

            @Override
            public void onBindData(CommonRVHolder<MediaBrowser.MediaItem> holder, MediaBrowser.MediaItem data,
                                   int position) {
                String title = data.getDescription().getTitle().toString();
                String author = data.getDescription().getSubtitle().toString();
                holder.setText(R.id.tv_musicinfo_title, title);
                holder.setText(R.id.tv_musicinfo_author, author);

                if (position == mCurrentIndex) {
                    holder.setVisibility(R.id.tv_playing, View.VISIBLE);
                } else {
                    holder.setVisibility(R.id.tv_playing, View.INVISIBLE);
                }
            }
        };
    }
}
